﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace game
{
    /// <summary>
    /// base class for "solid" model objects, i.e. asteroids and ships,
    /// and not skyboxes and planets (unless planets are collidable and destroyable)
    /// </summary>
    public class RegularModelObject : ModelObject
    {
        public float Health { get; protected set; }
        public float MaxHealth { get; protected set; }
        protected float damage = 0.0f;

        public RegularModelObject(Scene scene, ModelUnit model, int layerIndex)
            : base(scene, model, layerIndex)
        {
            this.position = position;

            Health = MaxHealth = 1.0f;
        }

        public override void Collision(GameObject obj)
        {
            Health -= obj.GetDamage();
            if (Health <= 0)
            {
                Destroyed();
            }
        }

        public override float GetDamage()
        {
            return damage;
        }

        /// <summary>
        /// may be overriden to model different dying behaviur
        /// - like generating explosion in ships and asteroids
        /// </summary>
        protected virtual void Destroyed()
        {
            scene.RemoveObject(this);
            IsAlive = false;
            Explode();
        }

        protected virtual void Explode()
        {
        }
    }
}
